from django.db import models

# Create your models here.

class Gabusiness(models.Model):
    id = models.AutoField(primary_key=True)
    gabusinesstype_id = models.IntegerField(null=True, blank=True)
    gabizlocation_id = models.IntegerField(null=True, blank=True)
    bizname = models.CharField("Business Name",max_length=75)
    contactemail = models.CharField("Contact Email",max_length=50, blank=True)
    supportemail = models.CharField("Support Email",max_length=50, blank=True)
    contactname = models.CharField("Contact Name",max_length=60, blank=True)
    phonenumber = models.CharField("Phone Number",max_length=18, blank=True)
    faxnumber = models.CharField("Fax Number", max_length=18, blank=True)
    ein = models.CharField(max_length=30, blank=True)
    url = models.CharField("URL", max_length=150, blank=True)
    external_biz_id = models.CharField(max_length=90, blank=True)
    class Meta:
        db_table = u'gabusiness'

    def __unicode__(self):
      return self.bizname



class Gabizlocation(models.Model):
    id = models.AutoField(primary_key=True)
    gabusiness = models.OneToOneField(Gabusiness)
    latitude = models.FloatField("Latitude",null=True, blank=True)
    longitude = models.FloatField("Longitude",null=True, blank=True)
    city = models.CharField("City",max_length=150)
    state = models.CharField("State",max_length=6)
    zip = models.CharField("Zip Code", max_length=30)
    address_1 = models.CharField("Address", max_length=150)
    address_2 = models.CharField(max_length=150, blank=True)
    country = models.CharField(max_length=6)
    class Meta:    
        db_table = u'gabizlocation'

    def __unicode__(self):
        address = self.address_1 + ', '+  self.city + ', ' + self.state
        return address

class Gaevent(models.Model):
    id = models.AutoField(primary_key=True)
    eventname = models.CharField("Name",max_length=120)
    eventdescription = models.TextField("Description",blank=True)
    tickets = models.CharField(max_length=150, blank=True)
    icon = models.TextField(blank=True)
    gabusiness = models.ForeignKey(Gabusiness)
    gaeventlocation_id = models.IntegerField()
    supportemail = models.CharField("Support Email",max_length=150, blank=True)
    supportphone = models.CharField("Support Phone",max_length=45, blank=True)
    eventstartdate = models.DateField("Start Date")
    eventenddate = models.DateField("End Date",null=True, blank=True)
    eventstarttime = models.TimeField("Start Time") # This field type is a guess.
    eventendtime = models.TimeField("End Time",blank=True) # This field type is a guess.
    eventexpiration = models.DateTimeField(null=True, blank=True)
    is_active = models.IntegerField(null=True, blank=True)
    is_featured = models.IntegerField(null=True, blank=True)
    paid = models.IntegerField("Paid",null=True, blank=True)
    external_event_id = models.CharField(max_length=120, blank=True)
    class Meta:
        db_table = u'gaevent'

    def __unicode__(self):
        event = self.eventname + " (" + str(self.eventstartdate) + ")"
        return event

class Gaeventlocation(models.Model):
    id = models.AutoField(primary_key=True)
    gaevent = models.OneToOneField(Gaevent)#brings gaevents_idgaevents_id error up? django must add _id to end of it
    latitude = models.FloatField("Latitude",null=True, blank=True)
    longitude = models.FloatField("Longitude",null=True, blank=True)
    city = models.CharField("City",max_length=150)
    state = models.CharField("State",max_length=6)
    zip = models.CharField("Zip Code", max_length=30)
    address_1 = models.CharField("Address", max_length=150)
    address_2 = models.CharField(max_length=150, blank=True)
    country = models.CharField(max_length=6)
    class Meta:
        db_table = u'gaeventlocation'
    
    def __unicode__(self):
        address = self.address_1 + ', '+  self.city + ', ' + self.state
        return address
